package com.bw.wxy.mvp.model;

import com.bw.wxy.common.Api;
import com.bw.wxy.factroy.ChangFunction;
import com.bw.wxy.factroy.HttpCode;
import com.bw.wxy.factroy.HttpFactory;
import com.bw.wxy.factroy.HttpType;
import com.bw.wxy.mvp.model.entity.BaseEntity;
import com.bw.wxy.mvp.base.model.BaseModel;
import com.bw.wxy.mvp.contract.UserContract;
import com.bw.wxy.mvp.model.entity.ResponseUserEntity;

import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;
import okhttp3.RequestBody;

public class UserModel extends BaseModel implements UserContract.IUserModel {

    @Inject
    public UserModel(){}

    @Override
    public Observable<BaseEntity> requestUser(Map<String, Object> map) {
        int code = (int) map.get("code");
        map.remove("code");
        if (code==HttpCode.SELUSERCODE){
            RequestBody body=createBody(map);
            Observable<ResponseUserEntity> ob= HttpFactory.getInstance().factory(HttpType.TOKENTYPE)
                    .getRetrofit().create(Api.class).requestUser(body);
            return ob.map(new ChangFunction<ResponseUserEntity>());
        }
        return null;
    }

}

